package com.yamanyar.weebill.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.validator.NotNull;

/**
 * Action represents a step in the life of a task or bug. A task or bug can have
 * several <code>Action</code>'s to be performed in order to complete that
 * task or bug.
 * 
 * User may create <code>Action</code>s for a Bug like "New","In
 * Progress","Resolved","Closed". And you can assign listeners to these classes
 * so that for example you can send e-mail to some related participants when an
 * <code>Action</code> begins or ends.
 * 
 * <code>Action</code>s are grouped in <code>ActionPath</code> object and
 * each project should have at least one <code>ActionPath</code>.
 * 
 * <code>Action</code>s can only be performed with users of associated roles.
 * <code>Role</code>s are assigned to <code>Action</code>s in
 * <code>ActionPathElement</code> which is element in <code>ActionPath</code>
 * object. <code>ActionPath</code> object contains a set of
 * <code>ActionPathElement</code> in an ordered way.
 * 
 * Also you can register action listeners to <code>Action</code>s in
 * ActionPath. With listeners you can perform important issues like informing
 * related participant when a bug is resolved.
 * 
 * @see ActionPath
 * @see ActionPathElement
 * @author Kaan Yamanyar
 * 
 */
@Entity
public class Action implements java.io.Serializable {

	private static final long serialVersionUID = 574870955558281712L;

	private Long id;

	private String name;

	private String description;

	public Action() {
	}

	public Action(Long id, String name) {
		this.id = id;
		this.name = name;
	}

	public Action(Long id, String name, String description) {
		this.id = id;
		this.name = name;
		this.description = description;

	}

	/**
	 * 
	 * @return The id of action. Id is auto-generated by db.
	 */
	@Id
	@GeneratedValue
	public Long getId() {
		return this.id;
	}

	/**
	 * This method is not supposed to be called by a developer.
	 * 
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * 
	 * @return Name of the action. (max length is 50 chars.)
	 */
	@Column(length = 50, unique = true, nullable = false)
	@NotNull
	public String getName() {
		return this.name;
	}

	/**
	 * 
	 * @param name
	 *            Name of the action. Maxed allowed length is 50 chars.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Description of the action.
	 * 
	 * @return Description of the action which is maximum 400 chars long.
	 */
	@Column(length = 400)
	@NotNull
	public String getDescription() {
		return this.description;
	}

	/**
	 * 
	 * @param description
	 *            Description of the action which is max length is 400 chars.
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	@Override
	public int hashCode() {
		if (this.id == null) {
			return 0;
		}
		return (int) (this.id / 10) + 1;
	}

	@Override
	public String toString() {
		return this.name;
	}

}
